package com.ywgt.collection;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class MapSafe {
    public static void main(String[] args) {

        //Map<String, String> map=new HashMap<>();//加载因子16 初始化容量0.75
        //解决方法1：Map<String, String> map=new Hashtable<>();
        //解决方法2：Map<String, String> map= Collections.synchronizedMap(new HashMap<>());
        //解决方法3：
        Map <String, String> map=new ConcurrentHashMap<>();
        for (int i=0;i<10;i++){
            new Thread(()->{
                map.put(String.valueOf(Thread.currentThread().getName()), UUID.randomUUID().toString().substring(5));
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
